<template>
  <basic-container>
    <el-tabs type="border-card" class="informationLabel">
      <el-tab-pane label="产品标签(自定义)创建生成">
        <el-row :gutter="20">
          <el-col :span="11">
            <avue-form
              id="rawMaterialOtherForm"
              class="newFormStyle"
              ref="rawMaterialOtherForm"
              v-model="rawMaterialOtherForm"
              :option="rawMaterialOtherOption"
              @submit="rawMaterialOtherLabelGenerate"
            >
            </avue-form>
          </el-col>
          <el-col :span="12">
            <div class="sequenceInfo">
              <el-row>
                <el-col :span="15">
                  <print-template :url="url" ref="printInfo" templateType="MATERIAL" @getPrintInfo="getPrintInfo"></print-template>
                </el-col>
                <el-col :span="15" class="btn-group">
                  <el-button type="primary" size="small" @click="$refs.rawMaterialOtherForm.submit()">生成标签</el-button>
                  <el-button type="primary" size="small" @click="handlePrintTest">打印测试</el-button>
                  <el-button type="primary" size="small" @click="batchPrinting" :loading="btnLoading">打印标签</el-button>
                </el-col>
              </el-row>
            </div>
          </el-col>
        </el-row>
      </el-tab-pane>
    </el-tabs>

    <common-modal-template ref="commonModalTemplate" :option="tableOption" @getSelectedRows="getSelectedRows" :key="timer" @newKey="newKey"></common-modal-template>
    <el-tabs type="border-card" class="informationLabel mt8">
      <el-tab-pane label="产品标签(自定义)创建记录">
        <avue-crud
          :defaults.sync="recordDefaults"
          class="serialNoGenerationRecord"
          ref="serialNoGenerationRecord"
          :table-loading="loading"
          :option="serialNoGenerationRecordOption"
          :data="serialnoData"
          :row-style="rowStyle"
          @row-click="serialnoRowClick"
        >
          <template slot-scope="{ row }" slot="menu">
            <div class="menu-option">
              <el-button icon="el-icon-printer" :disabled="row.isPrinted !== 1 || row.generationType === 'SCRAP'" size="small" type="text" @click="rowPrint(row)">
                重打
              </el-button>
            </div>
          </template>
          <!--          @selection-change="selectionChange"-->
          <!--          <template slot-scope="{ row }" slot="menuLeft">-->
          <!--            <div class="menu-option">-->
          <!--              <el-button type="primary" icon="el-icon-printer" size="small" @click="rowPrint('ALL')"> 打印全部 </el-button>-->
          <!--              <el-button type="primary" icon="el-icon-printer" size="small" @click="rowPrint('SELECTOION')"> 打印 </el-button>-->
          <!--            </div>-->
          <!--          </template>-->
        </avue-crud>
      </el-tab-pane>
    </el-tabs>

    <!-- 操作日志 -->
    <operation-log ref="operationLog"></operation-log>
    <!--重打弹窗-->
    <el-dialog append-to-body title="重打" v-if="printInfoModel" :visible.sync="printInfoModel" width="35%">
      <div style="display: flex; justify-content: center; margin-bottom: 10px">
        <span style="color: red">注：仅需修改流水号即可，重打的起始流水号和结束流水号需在原流水号范围内</span>
      </div>
      <avue-form ref="printForm" v-model="repeatPrintInfo" :option="printInfoOption"> </avue-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" @click="printSubmit"><i class="el-icon-printer"></i><span>重打</span></el-button>
        <el-button size="small" @click="printInfoModel = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </span>
    </el-dialog>
    <print-time-input-form :visible.sync="printDialog" :other-info-option="otherInfoOption" @printInfo="(otherInfo) => handlePrintSequence(otherInfo)"></print-time-input-form>
  </basic-container>
</template>

<script>
import { getRawMaterialOtherOption } from './internalBarcodeCreate.js';
import { showFailLog, showSuccessLog } from '@/util/helpers';
import { cumstomSequenceCreate, getSourceList, printSequence, printTest, sequenceAppendByPart, sequenceCreateByPart } from '@/api/warehouse/warehouse-label-create-print';
import CommonModalTemplate from '@/components/common-modal-template/common-modal-template.vue';
import OperationLog from '@/components/operation-log/operation-log';
import { getDetail as getSequencedefinitionDetail } from '@/api/admin/sequencedefinition';
import { getSeqNoRules } from '@/util/global';
import { getPrinter, packPrint, snPrint } from '@/api/admin/barcode-record';
import { sequencePrint } from '@/api/product/product-label-create-print';
import { mapGetters } from 'vuex';
import { getPrintFormMixin } from '@/mixins/getPrintFormMixin';
import printTimeInputForm from '@/components/print-time-input-form';
import PrintTemplate from '@/views/product/components/printTemplate';
export default {
  name: 'internalBarcodeCreate',
  components: {
    PrintTemplate,
    CommonModalTemplate,
    OperationLog,
    printTimeInputForm
  },
  mixins: [getPrintFormMixin],
  computed: {
    ...mapGetters(['userInfo'])
  },
  data() {
    return {
      url: '/api/mes-admin/labeltemplate/page?type=material&subType=work_in_progress&status=1',
      rawMaterialOtherForm: {}, //序列号生成信息,
      tableOption: {},
      timer: new Date().getTime(),
      loading: false,
      selectionInfo: {},
      selectionList: [],
      recordDefaults: {},
      serialNoGenerationRecordOption: {
        //工单产品序列号内容配置
        height: 300,
        calcHeight: 30,
        border: true,
        index: true,
        indexLabel: '序号',
        viewBtn: false,
        dialogClickModal: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        tip: false,
        refreshBtn: false, //刷新按钮是否显示
        columnBtn: false, //控制表格列是否显示按钮是否显示
        menu: true,
        highlightCurrentRow: true,
        column: [
          {
            label: '起始序列号',
            prop: 'sequenceNumberFrom'
          },
          {
            label: '结尾序列号',
            prop: 'sequenceNumberTo'
          },
          {
            label: '序列号数量',
            prop: 'quantity'
          },
          {
            label: '生成时间',
            prop: 'createTime'
          },
          {
            label: '生成类型',
            prop: 'generationType',
            html: true,
            formatter: (val) => {
              switch (val.generationType) {
                case 'NORMAL':
                  return '正常';
                case 'SCRAP':
                  return '报废';
                case 'APPEND':
                  return '增补';
                case 'REPLACE':
                  return '置换';
                case 'REVORK':
                  return '撤销';
                default:
                  break;
              }
            }
          },
          {
            label: '操作人',
            prop: 'operatorName'
          },
          {
            label: '备注',
            prop: 'remark'
          },
          {
            label: '状态',
            prop: 'isPrinted',
            html: true,
            formatter: (val) => {
              switch (val.isPrinted) {
                case 0:
                  return `<span class="text-yellow">未打印</span>`;
                case 1:
                  return `<span class="text-green">已打印</span>`;
                case 2:
                  return `<span class="text-red">部分打印</span>`;
                default:
                  return `<span class="text-red">报废</span>`;
                  break;
              }
            }
          }
        ]
      },
      sequenceRuleInfo: {}, //产品序列号规则信息
      serialnoData: [],
      printInfo: {}, //打印机打印模版信息
      printInfoModel: false,
      repeatPrintInfo: {},
      printInfoOption: {
        labelWidth: 150,
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: '起始流水号',
            prop: 'startSequenceNumber',
            span: 20
          },
          {
            label: '结束流水号',
            prop: 'endSequenceNumber',
            span: 20
          },
          {
            label: '标签模版',
            prop: 'labelTemplateName',
            span: 20,
            type: 'search',
            placeholder: '请选择 标签模板',
            disabled: true,
            rules: [
              {
                required: true,
                message: '请选择标签模板',
                trigger: 'blur'
              }
            ],
            appendClick: () => {
              this.openLabelTemplateModal();
            }
          },
          {
            label: '打印机',
            prop: 'equipmentName',
            span: 20,
            type: 'search',
            placeholder: '请选择 打印机',
            disabled: true,
            rules: [
              {
                required: true,
                message: '请选择打印机',
                trigger: 'blur'
              }
            ],
            appendClick: () => {
              this.openPrintersModal();
            }
          }
        ]
      },
      rawMaterialOtherOption: getRawMaterialOtherOption(this) //序列号生成信息配置内容
    };
  },
  methods: {
    rawMaterialOtherLabelGenerate(row, done) {
      const { workOrderId = '', suffix = '', quantity = '', startSequenceNo = '', hexString = '', prefix = '', incrementQty = '', remark = '' } = this.rawMaterialOtherForm;
      const params = {
        workOrderId,
        suffix,
        quantity,
        startSequenceNo,
        hexString,
        prefix,
        incrementQty,
        remark
      };
      // this.rawMaterialOtherForm['timeConfig'] = this.timeConfig;
      cumstomSequenceCreate(params).then(
        (res) => {
          this.getSequenceRecordById(workOrderId);
          this.$message({
            type: 'success',
            message: res.data.msg
          });
          showSuccessLog(res.data.msg);
          done();
        },
        (error) => {
          showFailLog(error.data.msg);
          done();
        }
      );
    },
    //打印测试
    handlePrintTest() {
      if (!this.printInfo.printersId) {
        this.$message({
          type: 'warning',
          message: '请选择打印机！'
        });
        return;
      }
      if (!this.printInfo.labelTemplateId) {
        this.$message({
          type: 'warning',
          message: '请选择标签模版！'
        });
        return;
      }
      let params = {
        printId: this.printInfo.printersId,
        labelTemplateId: this.printInfo.labelTemplateId
      };
      printTest(params).then(
        (res) => {
          this.$message({
            type: 'success',
            message: res.data.msg
          });
          showSuccessLog(res.data.msg);
        },
        (error) => {
          showFailLog(error.data.msg);
        }
      );
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    /**
     * 标签打印
     */
    batchPrinting() {
      try {
        if (!Object.keys(this.selectionInfo).length) {
          this.$message({
            type: 'warning',
            message: '请选择一条生产记录'
          });
          return;
        }
        if (!this.printInfo.printersId) {
          this.$message({
            type: 'warning',
            message: '请选择打印机！'
          });
          return;
        }
        if (!this.printInfo.labelTemplateId) {
          this.$message({
            type: 'warning',
            message: '请选择标签模版！'
          });
          return;
        }
        if (!this.fieldList.length) {
          this.handlePrintSequence();
        } else {
          // 当标签模版绑定了数据源且设置了数据 打开其他信息弹窗
          this.printDialog = true;
        }
      } catch (e) {
        console.warn(e);
      }
    },
    handlePrintSequence(otherInfo = {}) {
      let params = {
        equipmentId: this.printInfo.printersId,
        labelTemplateId: this.printInfo.labelTemplateId,
        workOrderId: this.rawMaterialOtherForm.workOrderId,
        sequenceGenerationId: this._get(this.selectionInfo, 'id', '')
      };
      if (Object.keys(otherInfo).length) {
        params.printInput = JSON.stringify(otherInfo);
      }
      sequencePrint(params).then(
        (res) => {
          this.$message({
            type: 'success',
            message: res.data.msg
          });
          showSuccessLog(res.data.msg);
          this.getSequenceRecordById(this.rawMaterialOtherForm.workOrderId);
        },
        (error) => {
          showFailLog(error.data.msg);
        }
      );
    },
    // 重打
    async rowPrint(row) {
      // if (type === 'ALL') {
      // } else {
      // }
      try {
        const printer = await this.getDefaultPrinter();
        const { labelTemplateId = '', printerId = '', equipmentName = '', templateFileName = '' } = printer;
        this.repeatPrintInfo = {
          labelTemplateId: labelTemplateId,
          labelTemplateName: templateFileName,
          equipmentId: printerId,
          equipmentName
        };
      } catch (e) {
        console.warn(e);
      }
      this.repeatPrintInfo.startSequenceNumber = row.sequenceNumberFrom;
      this.repeatPrintInfo.endSequenceNumber = row.sequenceNumberTo;
      this.repeatPrintInfo.generationId = row.id;
      this.printInfoModel = true;
    },
    async getDefaultPrinter() {
      const { user_id } = this.userInfo;
      try {
        const res = await getPrinter({ id: user_id });
        return res.data.data;
      } catch (e) {
        console.warn(e);
      }
    },
    printSubmit() {
      this.$refs.printForm.validate(async (valid, done) => {
        if (valid) {
          try {
            const params = {
              ...this.repeatPrintInfo,
              fromSequenceNumber: this.repeatPrintInfo.startSequenceNumber,
              toSequenceNumber: this.repeatPrintInfo.endSequenceNumber
            };
            delete params.startSequenceNumber;
            delete params.endSequenceNumber;
            const res = await snPrint(params);
            this.$refs.printForm.resetFields();
            this.printInfoModel = false;
            this.$message({
              type: 'success',
              message: '重打成功'
            });
            this.getSequenceRecordById(this.rawMaterialOtherForm.workOrderId);
          } catch (e) {
            console.warn(e);
          }
        }
      });
    },
    /**
     * 获取选择的模态框行数据
     */

    getSelectedRows(rowData) {
      switch (this.modalName) {
        case 'workorderModal':
          this.$refs.rawMaterialOtherForm.resetForm();
          this.rawMaterialOtherForm.hexType = '10';
          this.rawMaterialOtherForm.hexString = '0123456789';
          this.rawMaterialOtherForm.incrementQty = 1;
          this.rawMaterialOtherForm.workOrderId = this._get(rowData, 'id', '');
          this.rawMaterialOtherForm.workOrderNo = this._get(rowData, 'orderNo', '');
          this.rawMaterialOtherForm.partNo = this._get(rowData, 'partNo', '');
          this.rawMaterialOtherForm.partName = this._get(rowData, 'partName', '');
          this.rawMaterialOtherForm.partModel = this._get(rowData, 'partModel', '');
          this.rawMaterialOtherForm.planQuantity = this._get(rowData, 'planQuantity', '');
          //    this.rawMaterialOtherForm.receivingId = this.rawMaterialOtherForm.workOrderId = this._get(rowData, 'id', '');
          // if (this.rawMaterialOtherForm.sequenceDefinitionId) {
          //   this.getSequencedefinitionDetail(this.rawMaterialOtherForm.sequenceDefinitionId);
          // }
          this.getSequenceRecordById(this.rawMaterialOtherForm.workOrderId);
          break;
        case 'serialnoModal':
          this.rawMaterialOtherForm.sequenceName = this._get(rowData, 'name', '');
          this.rawMaterialOtherForm.sequenceDefinitionId = this._get(rowData, 'id', '');
          break;
        case 'printersModal':
          this.repeatPrintInfo.equipmentId = this._get(rowData, 'id', '');
          this.repeatPrintInfo.equipmentName = this._get(rowData, 'name', '');
          break;
        case 'labelTemplateModal':
          this.repeatPrintInfo.labelTemplateId = this._get(rowData, 'id', '');
          this.repeatPrintInfo.labelTemplateName = this._get(rowData, 'fileName', '');
          break;
        default:
          break;
      }
    },
    /*
     * 根据序列号规则ID查询详情
     */
    getSequencedefinitionDetail(sequencedefinitionId) {
      getSequencedefinitionDetail(sequencedefinitionId).then((res) => {
        this.$set(this.sequenceRuleInfo, 'name', this._get(res, 'data.data.name', ''));
        this.$set(this.sequenceRuleInfo, 'sequenceNoFormat', this._get(res, 'data.data.sequenceNoFormat', ''));
        this.$set(this.sequenceRuleInfo, 'sequenceNoFormatZh', this._get(res, 'data.data.sequenceNoFormatZh', ''));
        this.$set(this.sequenceRuleInfo, 'seqNoFormatDemo', this._get(res, 'data.data.seqNoFormatDemo', ''));
        this.$set(this.sequenceRuleInfo, 'containsSequenceNo', this._get(res, 'data.data.containsSequenceNo', true));
        this.$set(this.sequenceRuleInfo, 'charactersCount', this._get(res, 'data.data.charactersCount', 0));
        this.seqNoConvert();
      });
    },

    serialnoRowClick(row) {
      this.selectionInfo = row;
      this.$refs.serialNoGenerationRecord.toggleSelection(row);
    },
    rowStyle({ row, column, rowIndex }) {
      if (!Object.keys(this.selectionInfo).length) {
        return;
      }
      if (Object.keys(this.selectionInfo).length && row.id === this.selectionInfo.id) {
        return {
          backgroundColor: '#caf982'
        };
      }
    },
    /*
     * 序列号规则转换中文
     * @param sequenceNoValue 序列号规则
     * @param sequenceNo 序列号规则起始流水号
     */
    seqNoConvert() {
      let seqNoRules = [];
      this._forEach(getSeqNoRules(), (item) => {
        seqNoRules = [...seqNoRules, ...item.value];
      });
      let splitList = this.sequenceRuleInfo.sequenceNoFormat.split('');
      //在[前加空格  ]后加空格
      splitList = splitList.map((item) => {
        if (item === '[') {
          return ' [';
        } else if (item === ']') {
          return '] ';
        } else {
          return item;
        }
      });
      splitList = splitList.join('');
      //按空格拆分字符串
      splitList = splitList.split(' ');
      //匹配中文
      let splitArr = this._map(splitList, (item) => {
        this._forEach(seqNoRules, (ele) => {
          if (item === ele.key) {
            item = ele.value;
          }
        });
        return item;
      });
      //去除空格
      splitArr = splitArr.filter(function (s) {
        return s && s.trim();
      });
      //转换后给序列号规则赋值
      this.sequenceRuleInfo.sequenceNoFormatZh = splitArr.join('+');

      let splitDemoArr = this._map(splitList, (item) => {
        this._forEach(seqNoRules, (ele) => {
          if (item === ele.key) {
            let currentDate = new Date();
            switch (item) {
              case '[YY]':
                let year = String(currentDate.getFullYear());
                item = year.substring(2, year.length);
                break;
              case '[YYYY]':
                item = currentDate.getFullYear();
                break;
              case '[M]':
                let month = currentDate.getMonth() + 1;
                if (month < 10) {
                  item = '0' + month;
                } else {
                  item = month;
                }
                break;
              case '[W]':
                let today = new Date();
                let firstDay = new Date(today.getFullYear(), 0, 1);
                let dayOfWeek = firstDay.getDay();
                let spendDay = 1;
                if (dayOfWeek != 0) {
                  spendDay = 7 - dayOfWeek + 1;
                }
                firstDay = new Date(today.getFullYear(), 0, 1 + spendDay);
                let d = Math.ceil((today.valueOf() - firstDay.valueOf()) / 86400000);
                let week = Math.ceil(d / 7);
                week = week + 1;
                if (week < 10) {
                  item = '0' + week;
                } else {
                  item = week;
                }
                break;
              case '[D]':
                let day = currentDate.getDate();
                if (day < 10) {
                  item = '0' + day;
                } else {
                  item = day;
                }
                break;
              case '[S]':
                if (this.sequenceRuleInfo.sequenceNo) {
                  item = this.sequenceRuleInfo.sequenceNo;
                } else {
                  item = this.sequenceRuleInfo[ele.code];
                }
                break;
              case '[WO]':
                if (this.model.workOrderNo) {
                  item = this.model.workOrderNo;
                } else {
                  item = '[WO]';
                }
                break;
              default:
                if (ele.code) {
                  item = this.sequenceRuleInfo[ele.code];
                }
                break;
            }
          }
        });
        return item;
      });
      splitDemoArr = splitDemoArr.filter(function (item) {
        return String(item) && String(item).trim();
      });
      this.sequenceRuleInfo.seqNoFormatDemo = splitDemoArr.join('');
    },
    /**
     * 获取打印机和打印模版信息
     */
    getPrintInfo(printInfo) {
      if (printInfo.printersId) {
        this.printInfo.printersId = printInfo.printersId;
      }
      if (printInfo.labelTemplateId) {
        this.printInfo.labelTemplateId = printInfo.labelTemplateId;
        const dataId = printInfo.dataId;
        if (dataId) {
          this.getDetail(printInfo.dataId);
        } else {
          this.fieldList = [];
        }
      }
    },
    openCommonModal(type) {
      this.modalName = 'workorderModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择工单号（双击进行选择）',
        url: ' /api/mes-product/work-order/page',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '生产订单',
            prop: 'productionOrderNo',
            search: true,
            searchType: 'input',
            type: 'search'
          },
          {
            label: '生产工单',
            prop: 'orderNo',
            search: true
          },
          {
            label: '工单类型',
            prop: 'orderType',
            type: 'select',
            rules: [
              {
                required: true,
                message: '请选择工单类型',
                trigger: 'change'
              }
            ],
            dicUrl: '/api/blade-system/dict/dictionary?code=order_type',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '工单数量',
            prop: 'planQuantity',
            type: 'number',
            minRows: 1
          },
          {
            label: '产品编码',
            prop: 'partNo',
            search: true,
            searchType: 'input',
            type: 'search'
          },
          {
            label: '产品名称',
            prop: 'partName',
            search: true
          },
          {
            label: 'BOM版本',
            prop: 'bomVersion',
            type: 'search'
          },
          {
            label: '派工产线',
            prop: 'productionLineName',
            search: true,
            searchType: 'input',
            type: 'search'
          },
          {
            label: '计划开始时间',
            prop: 'planStartDate',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            valueFormat: 'yyyy-MM-dd HH:mm:ss'
          },
          {
            label: '计划结束时间',
            prop: 'planEndDate',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            valueFormat: 'yyyy-MM-dd HH:mm:ss'
          },
          {
            label: '制定人',
            prop: 'creatorName',
            disabled: true
          },
          {
            label: '状态',
            prop: 'status',
            type: 'select',
            search: true,
            dicData: [
              {
                label: '待排程',
                value: 1
              },
              {
                label: '待生产',
                value: 2
              },
              {
                label: '生产中',
                value: 3
              },
              {
                label: '完工',
                value: 4
              },
              {
                label: '锁定',
                value: 5
              },
              {
                label: '强制完工',
                value: 6
              }
            ]
          },
          {
            label: '备注',
            prop: 'remark',
            type: 'textarea'
          }
        ]
      };
    },

    /**
     * 打开序列号规则选择模态框
     */
    openSerialnoCommonModal() {
      this.modalName = 'serialnoModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择序列号规则（双击进行选择）',
        url: '/api/mes-admin/sequencedefinition/page',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '序列号规则名称',
            prop: 'name',
            search: true,
            searchLabelWidth: 150,
            searchSpan: 8
          },
          {
            label: '序列号规则编码',
            prop: 'code',
            search: true,
            searchLabelWidth: 150,
            searchSpan: 8
          },
          {
            label: '进制符',
            prop: 'hexString'
          },
          {
            label: '起始流水号',
            prop: 'startSequenceNo'
          },
          {
            label: '序列号规则',
            prop: 'sequenceNoFormat'
          }
        ]
      };
    },

    /**
     * 获取打印机
     */
    openPrintersModal() {
      this.modalName = 'printersModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择打印机（双击进行选择）',
        url: '/api/mes-product/ems-equipment/page?type=PRINTER',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '打印机编码',
            prop: 'code',
            search: true,
            searchLabelWidth: 110
          },
          {
            label: '打印机名称',
            prop: 'name',
            search: true,
            searchLabelWidth: 110
          }
        ]
      };
    },
    /**
     * 打开标签模板模态框
     */
    openLabelTemplateModal() {
      this.modalName = 'labelTemplateModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择标签模版（双击进行选择）',
        url: '/api/mes-admin/labeltemplate/page?type=material&subType=work_in_progress&status=1',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '标签名称',
            prop: 'fileName',
            search: true
          },
          {
            label: '标签代码',
            prop: 'code',
            search: true
          },
          {
            label: '版本名称',
            prop: 'revision'
          },
          {
            label: '缩略图',
            prop: 'thumbnailUrl'
          },
          {
            label: '打印标签',
            prop: 'fileUrl'
          }
        ]
      };
    },
    newKey() {
      this.timer = new Date().getTime();
    },
    /**
     * 根据id获取所有生成记录
     */
    getSequenceRecordById(id) {
      let params = {
        sourceId: id,
        generationType: 'NORMAL',
        sourceType: 'PRODUCT_WORK_ORDER'
      };
      this.loading = true;
      getSourceList(params)
        .then(
          (res) => {
            this.serialnoData = this._get(res, 'data.data', []);
          },
          (error) => {
            this.serialnoData = [];
          }
        )
        .finally((this.loading = false));
    },
    customValidator(rule, value, callback) {
      if (Number(value) && Number(value) < 0) {
        callback('起始流水号需为大于0的正整数');
      } else {
        callback();
      }
    }
  }
};
</script>

<style scoped lang="scss">
.sequenceInfo {
  table {
    width: 100%;
    height: auto;
    margin-bottom: 10px;
    font-size: 14px;
    th {
      border: 1px solid #ebeef5;
      background: #fafafa;
      height: 30px;
    }
    tr {
      border: 1px solid #ebeef5;
    }
    td {
      border: 1px solid #ebeef5;
      height: auto;
      text-align: center;
    }
    p {
      margin-left: 30px;
    }
  }
}

//.newFormStyle {
//  ::v-deep .el-form-item--small.el-form-item {
//    margin-bottom: 5px;
//  }
//  ::v-deep .el-input--small input {
//    height: 30px;
//    line-height: 30px;
//  }
//}
.generateSerialNoInfo {
  div {
    margin: 5px 10px;
  }
}
.printButton {
  text-align: right;
}
.btn-group {
  display: flex;
  justify-content: center;
}
.mt8 {
  margin-top: 8px;
}

::v-deep .el-table__body tr.current-row > td {
  background-color: transparent;
}
::v-deep .avue-crud__menu {
  display: none;
}
</style>
